//  Lyn Emblem
//  Created by Shan Pratapagiri and Bassam Saeed.

import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;

public class Emblem extends JFrame implements KeyListener
{
	static final int WIDTH = 800;
	static final int HEIGHT = 300;
	static Graphics2D graphics;

	static Random rand = new Random();
	static PaintSurface canvas;
	
	public static void main(String[] args)
	{
		new Emblem();
	}
	
	public Emblem()
	{
		this.setSize(WIDTH, HEIGHT);
		this.setTitle("Lyn Emblem");
		this.setBackground(Color.BLACK);
		this.setResizable(false);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		canvas = new PaintSurface();

		canvas.setFocusable(true);
		canvas.addKeyListener(this);
		
		this.add(canvas);
		this.setVisible(true);

		while(true)
		{
			canvas.repaint();
		}
	}
	
	public void keyPressed (KeyEvent e)
	{
		int keyCode = e.getKeyCode();
		
		if (keyCode == KeyEvent.VK_RIGHT)
		{
			canvas.lyn.setXSpeed(2);
			canvas.lyn.setPosition(1);
		}
		else if (keyCode == KeyEvent.VK_DOWN)
			canvas.lyn.setPosition(3);
		else if (keyCode == KeyEvent.VK_LEFT)
		{
			canvas.lyn.setXSpeed(-2);
			canvas.lyn.setPosition(2);
		}
		
		if (keyCode == KeyEvent.VK_A)
			canvas.lyn.setPosition(4);
	}
	
	public void keyReleased (KeyEvent e)
	{
		int keyCode = e.getKeyCode();
		
		if (keyCode == KeyEvent.VK_DOWN)
			canvas.lyn.setPosition(0);
		else if (keyCode == KeyEvent.VK_RIGHT || keyCode == KeyEvent.VK_LEFT)
		{
			canvas.lyn.setXSpeed(0);
			canvas.lyn.setPosition(0);
		}
	}
	
	public void keyTyped (KeyEvent e){}
	
	private class PaintSurface extends JComponent
	{
	
		Lyndis lyn = new Lyndis();
		Enemy bandit = new Enemy();
	
		public void paint(Graphics g)
		{
			graphics = (Graphics2D)g;
			
			graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
			
			graphics.drawImage(lyn.img, lyn.getXSpeed(), lyn.getYSpeed(), this);
			graphics.drawImage(bandit.img, bandit.getXSpeed(), bandit.getYSpeed(), this);
			
			lyn.move();
		}
		
	}
}